<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		// 1. async 只加载外部脚本。
		// 2. defer 只能IE使用，在文档解析完成之后才会执行。
		// 3.
		function loadScript(url, fun) {
			var script = document.createElement('script');
			if (script.readyState) { // IE兼容性		
				script.onreadystatechange = function () {
					if (script.readState == 'complete' || script.readState == 'loaded') {
						fun();
					}
				}
			} else {
				script.onload = function () {
					fun();
				}
			}
			script.src = url;
			document.head.appendChild(script);
		}
		loadScript('index.js', function () { a(); })
	</script>
</body>

</html>